<!DOCTYPE html>
<html lang="en">
<head>
    <title>药房收费</title>
    <meta name="renderer" content="webkit" >
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=Edge">
    <!--<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">-->
    <meta name="viewport" content="width=device-width,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
    <base href="<%=url%>">
    <script src="https://lib.baomitu.com/jquery/3.4.1/jquery.min.js"></script>
    <link type="text/css" href="/css/cure.css" rel="stylesheet">
    <script src="https://lib.baomitu.com/jquery/3.4.1/jquery.min.js"></script>
    <script src="https://lib.baomitu.com/layui/2.6.5/layui.min.js"></script>
    <link href="https://lib.baomitu.com/layui/2.6.5/css/layui.min.css" rel="stylesheet">
</head>
<style type="text/css">
    #input-limit{
        height: 30px;
        background-color: #1e9fff;
        color: whitesmoke;
        width: 60px;
        border:1px #1e9fff;
        border-radius: 4px;
    }

    #input-limit:hover{
        background-color:#bbdaff;
    }
    /*.layui-layer{*/
        /*top: 100px !important;*/
    /*}*/
</style>
<body>
<div class="layui-row layui-col-space10">
    <div class="layui-col-md6">
        <div id="handy-left">
            <div id="handy-01">
                <br>
                <span style="font-size: 40px;font-weight:bold;"> XXX医院</span><br/><br>
                <span style="font-size: 25px;">普通电子处方药单 </span>
                <br>
                <br/>
                处方号<input type="text"  id="ydbh"  style="width: 140px" readonly="readonly">
                患者卡号<input type="text"  style="width: 91px" readonly="readonly" id="visid">
                <br> <br>
                患者姓名<input type="text" id="uname"  style="width: 91px" readonly="readonly">
                开药时间<input type="text"  id="createDate" style="width: 133px" readonly="readonly">
                <br> <br>
                <!--  初步诊断<input type="text" id="diagnosisResult" style="width:505px" readonly="readonly">-->
                <br>
                <hr style="margin-right: 50px;margin-left: 50px;">
            </div>
            <div id="tbody">
                <span style="float: left;font-size: 65px;margin-left: 100px;">R</span>
                <span style="float: left;font-size: 80px;">p</span>
                <span style="float: left;font-size: 80px;margin-top: 22px;">:</span>
                <br><br><br><br><br><br><br><br>
                <div id="tbody01"  >
                </div>
            </div>
            <hr style="margin-right: 20px;margin-left: 20px;">
            <div id="tfoot">

                <div id="tfoot_one"><span style="float: left">主治医生<input id="did" type="text" th:value="${dbs.name}"   style="width: 91px" readonly="readonly"></span>  <span style="float: right;margin-right: 20px;">就诊时间:<input type="text"  th:value="${#dates.format(new java.util.Date().getTime(), 'yyyy-MM-dd')}"  style="width: 91px;border: 0px" readonly="readonly"></span></span></div>
                <br> <br><br>
                <div style="text-align: center;color: red;">*注：本处方为临床初步诊断</div>
            </div>
        </div>
    </div>
    <div class="layui-col-md6">
        <div id="right_quan" style="border: 1px solid black;margin-top: 20px">

            <div>
                <div style="text-align: center;font-size: 35px"><b>药单查询</b></div>
                <div style="padding-left: 50px;text-align: center">
                    <!--<a style="margin-left: 50px"><span style="font-size: 18px;margin-right: 10px">ID查询:</span><input type="text" placeholder="请输入ID" id="input-uid" style="height: 30px"></a>-->
                    <input type="text" placeholder="请输入患者处方单号" id="input-diaid" style="height: 30px;border: 1px solid ;margin: 20px"></a>
                    <button   id="input-limit">搜索</button>
                </div>
            </div>
            <div style="border: black 1px solid;padding: 20px;margin-top: 20px;overflow:auto;-ms-overflow-style: none;">
                <div style="text-align: center;font-size: 35px;"><b>药单详情展示</b></div>
                <div >
                    <table class="layui-table" lay-even="" lay-skin="row">
                        <tr>  <th>药品名称</th>
                            <th>药品数量</th>
                            <th>药品单价</th>
                            <th>药品小计</th></tr>
                        <tbody id="bodybut">

                        </tbody>
                        <tr >
                            <td colspan="4" style="text-align: center">总计:<span id="zong">00.00</span>元</td>
                        </tr>
                    </table>
                </div>

                <div style="text-align: center;font-size: 25px;float: right"><button id="qybtn" type="button" class="layui-btn"><b>取药收费</b></button></div>
            </div>

        </div>

    </div>
</div>
</div>
</body>
</html>
<script>
    $("#input-limit").click(function () {
        var diaid = $("#input-diaid").val();
        bdempty();//清空所有表单
        $.get("/Medcharge/MedChargeAll", {diaid: diaid}, function (data) {
            if(data==null||data==""){
                layer.open({
                    title:'错误提示'
                    ,content:'该药单不存在，，或该患者已取药！！'
                    ,icon:2
                })
                return false;
            }
            var u = 0;
            var e = 1;
            for (var i = 0; i < data.length; i++) {
                u += data[i].subtotal
                var tr = "<tr>"
                tr += "<td>" + data[i].ypname + "</td>"
                tr += "<td>" + data[i].ypnum + data[i].unitname + "</td>"
                tr += "<td>" + data[i].price + "元/" +data[i].unitname+"</td>"
                tr += "<td>" + data[i].subtotal + "元" + "</td>"
                tr += "</tr>";
                $("#bodybut").append(tr);
                var div = '<div ><li>' + e + '<span id="a" style="margin-left:100px;margin-right: 20px">'
                    + data[i].ypname + '</span><span> ' + "*" + data[i].ypnum + " " + data[i].unitname + '</span></li><br/><span style="margin: 10px 0 10px 5px;">用法：<sapn>'
                    + data[i].take + '</sapn></span></div><br/>';
                $("#tbody01").append(div)
                e++;
            }
            $("#ydbh").val(data[0].diaid);
            $("#did").val(data[0].did);
            $("#createDate").val(myDateFomat1(data[0].yptime))
            $("#uname").val(data[0].uname);
            $("#visid").val(data[0].visid);
            $("#zong").text(u)
        })
    })
</script>
<script>
    //收錢

    $("#qybtn").click(function () {
        var diaid= $("#ydbh").val();
        var visid=$("#visid").val();
        var price=$("#zong").text();
        var usefor="药品购买";
        if(diaid==null||diaid==""){
            layer.open({
                title:'错误提示'
                ,content:'尚未存在药单，请先查找正确的药单！！'
                ,icon:2
            })
            return false;
        }
        layer.confirm('本次药品费用为'+price+'元是否确认支付？', function (index) {
            $.get("/Medcharge/dginsert",{visid:visid,diaid:diaid,price:price,usefor:usefor},function (data) {
                if(data==true){
                    layer.msg('取药成功');
                    bdempty();
                }else {
                    layer.open({
                        title:'错误提示'
                        ,content:'当前账户余额不足，请先进行充值！！'
                        ,icon:2
                    })
                }
            })


        })
    })
    //清空表单
    function bdempty() {
        $("#bodybut").empty();
        $("#tbody01").empty();
        $("#zong").text("00.00");
        $("#ydbh").val("");
        $("#did").val("");
        $("#createDate").val("");
        $("#uname").val("");
        $("#visid").val("");
    }
</script>

<script>
    function myDateFomat1(t){
        var date=new Date(t);
        var y=date.getFullYear();
        var m=(date.getMonth()+1).toString().padStart(2,"0");
        var d=(date.getDate()).toString().padStart(2,"0");
        return y+"-"+m+"-"+d;
    }
    function myDateFomat2(t){
        var date=new Date(t);
        var y=date.getFullYear();
        var m=(date.getMonth()+1).toString().padStart(2,"0");
        var d=date.getDate().toString().padStart(2,"0");
        var h=date.getHours().toString().padStart(2,"0");
        var f=date.getMinutes().toString().padStart(2,"0");
        var s=date.getSeconds().toString().padStart(2,"0");
        return y+"-"+m+"-"+d+" "+h+":"+f+":"+s;
    }
</script>
<script>
    setInterval(function () {
        let date=new Date();
        $(".datetime1").text(myDateFomat2(date))
    },1000)

</script>